﻿using System;
using System.Data;
using System.Collections.Generic;

using System.Text;

namespace Model
{
    public class ContactModel:BaseModel
    {
        public const string TABLE_NAME = "Contact";
        public const string CONTACT_IT_FIELD = "AutoId";
        public const string FIRST_NAME_FIELD = "FirstName";
        public const string LAST_NAME_FIELD = "LastName";

        public const string EMAIL_FIELD = "Email";
        public const string PHONE_FIELD = "Phone";
        public const string CONTACT_TYPE_ID_FIELD = "ContactTypeId";

        public const string CONTACT_ID_FIELD = "TypeId";
        public const string CONTACT_NAME_FIELD = "TypeName";

        public ContactModel()
            : base(TABLE_NAME, CONTACT_IT_FIELD)
        {
            
        }
        public DataRow GetContact(int contactId)
        {
            DataTable table = GetDataTable("GetContactByContactId", contactId);
            if (table != null && table.Rows.Count > 0)
            {
                return table.Rows[0];
            }
            return null;
        }

        public DataRow GetCreditCardByAccountId(int AccountId)
        {
            return GetDataRow("GetCardAccountInfo", AccountId);
        }

        public DataRow GetContactBillingAccount(int AccountId)
        {
            return GetDataRow(0, "GetAddressInfoBillingByAccountId", AccountId);
        }

        public DataRow InsertUpdateBillingAddress(int AccountId, int AddressId, string CompanyName, string FirstName, string LastName, string Email, string Phone, string Address, string Street1, string Street2, string City, string StateCode, string CountryCode, string ZipCode)
        {
            return GetDataRow("InsertUpdateBillingAddress", AccountId, AddressId, CompanyName, FirstName, LastName, Email, Phone, Address, Street1, Street2, City, StateCode, CountryCode, ZipCode);
        }

        public DataRow GetBankAccountInfoByAccountId(int AccountId)
        {
            return GetDataRow("GetBankAccountInfo", AccountId);
        }

        public DataRow GetAccountPaymentType(int AccountId)
        {
            return GetDataRow(0, "GetAccountPaymentType", AccountId);
        }

        public DataTable GetListCardType()
        {
            return GetDataTable("GetListCardAccountType");
        }

        public DataTable GetListBankAccountType()
        {
            return GetDataTable("GetListBankAccountType");
        }

        public DataTable GetListBankAccountCategory()
        {
            return GetDataTable("GetListBankAccountCategory");
        }

        public DataTable GetListContactType()
        {
            return GetDataTable("GetListContactType");
        }

        public DataTable InsertUpdateCardAccount(int AccountId, string CardHolder, string Number, int CardTypeId, int ExpDay, int ExpYear)
        {
            return GetDataTable("InsertUpdateCardAccount", AccountId, CardHolder, Number, CardTypeId, ExpDay, ExpYear);
        }

        public DataTable InsertUpdateBankAccount(int AccountId, string RountingNumber, string AccountNumber, int BankTypeId, int BankCategoryId)
        {
            return GetDataTable("InsertUpdateBankAccount", AccountId, RountingNumber, AccountNumber, BankTypeId, BankCategoryId);
        }
                
        public int InsertUpdateContact(int AccountId, int UserId, string FirstName, string LastName, string Email, string Phone, int ContactTypeId, int ContactId)
        {
            return ExecuteNonQuery("InsertUpdateContact", AccountId, UserId, FirstName, LastName, Email, Phone, ContactTypeId, ContactId);
        }

        public int InsertUpdateUserInfo(int AccountId, int UserId, string UserName, string Password, string FirstName, string LastName, string Email, string Phone, int IsAdmin)
        {
            return ExecuteNonQuery("InsertUpdateUserInfo", AccountId, UserId, UserName, Password, FirstName, LastName, Email, Phone, IsAdmin);
        }

        public DataTable GetListContactByAccountId(int AccountId)
        {
            return GetDataTable("GetListContactByAccountId", AccountId);
        }

        public void DeleteContactOfAccount(int AutoIdOfContact)
        {
            ExecuteNonDataQuery("DeleteContactOfAccount", AutoIdOfContact);
        }
        public int InsertUpdateAccountAddressById(int AccountId, int UserId, string FirstName, string LastName, string Email, string Phone, int ContactTypeId, int ContactId)
        {
            return ExecuteNonQuery("InsertUpdateAccountAddressById", AccountId, UserId, FirstName, LastName, Email, Phone, ContactTypeId, ContactId);
        }
        public int InsertUpdateAccountAddressAll(int AccountId, string AccountName, string FirstName, string LastName, string CompanyName, string Email, string Phone, string Address, string Street1,  string Street2, string City, string StateCode, string CountryCode, string ZipCode)
        {
            return ExecuteNonQuery("InsertUpdateAccountAddressAll", AccountId, AccountName, FirstName, LastName, CompanyName, Email, Phone, Address, Street1, Street2, City, StateCode, CountryCode, ZipCode);
        }
    }
}
